package com.uyii.virtualthread.demos.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PerformanceTestController {
    private final PerformanceTestService performanceTestService;

    @Autowired
    public PerformanceTestController(PerformanceTestService performanceTestService) {
        this.performanceTestService = performanceTestService;
    }

    // 测试传统线程池性能
    @GetMapping("/testTraditionalThreads")
    public String testTraditionalThreads() throws InterruptedException {
        performanceTestService.testTraditionalThreads();
        return "传统线程池性能测试已完成";
    }

    // 测试虚拟线程池性能
    @GetMapping("/testVirtualThreads")
    public String testVirtualThreads() {
        performanceTestService.testVirtualThreads();
        return "虚拟线程池性能测试已完成";
    }
}